package cn.thoughtworks.school.usercenter.utils;

import java.sql.Timestamp;
import java.util.Calendar;

public class Tool {
    public static Boolean isExpired(Timestamp startTimestamp, Long duration){
        Long currentTimeStamp = getUTCTimeStamp();
        Long durationMillis = duration * 1000;
        Long startTimeStamp = startTimestamp.getTime();
        return currentTimeStamp - startTimeStamp > durationMillis;
    }

    public static Long getUTCTimeStamp() {
        Long currentTimeStamp = System.currentTimeMillis();
        Calendar cal = Calendar.getInstance();
        int offset = cal.getTimeZone().getOffset(currentTimeStamp);
        currentTimeStamp =  currentTimeStamp - offset;
        return currentTimeStamp;
    }
}
